﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace HenrryTools.WinFormTools
{
    public partial class Sm4CodeKey : Form
    {
        public Sm4CodeKey()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 委托
        /// </summary>
        public Action<string> AfterChangeTextDel { get; set; }

        /// <summary>
        /// 新增密钥
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtCodeKey.Text))
            {
                lableMessage.Text = "你的输入为空！";
                return;
            }
            string CodeList = string.Empty;
            //如果有值
            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.SM4CodeKey))
            {
                CodeList += Properties.Settings.Default.SM4CodeKey + ",";
            }
            CodeList += txtCodeKey.Text;
            AfterChangeTextDel(CodeList);//执行委托
            Properties.Settings.Default.SM4CodeKey = CodeList;//保存在Settings
            Properties.Settings.Default.Save();//保存
            lableMessage.Text = "保存成功！";
            lableMessage.ForeColor = Color.Red;
        }
        /// <summary>
        /// 取消
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnback_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
